package com.woniuxy.threadmethods;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 使用interrupt 打断线程  使用isInterrupted获得状态 如果为true表示被打断了
 *          wait、join、sleep被打断后值是false 只有正常的执行线程打断了才是true
 * <P> Date: 2022/4/6:19:03
 * <P> Description:
 */
@Slf4j(topic = "c.Test12")
public class Test12 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            while (true) {
                boolean interrupted = Thread.currentThread().isInterrupted();
                if(interrupted){
                    log.debug("被打断了 正在退出");
                    break;
                }
            }
        },"t1");
        t1.start();

        Thread.sleep(1000);

        log.debug("interrupt");
        t1.interrupt();



    }
}
